
FUNCTION string inputController (_vector3D*  currentDirection, string currentState)
PRIVATE
	_vector3D SOUTHd =  0, 0, 1;
	_vector3D NORTHd = 0, 0, -1;
	_vector3D WESTd = -1, 0, 0;
	_vector3D EASTd = 1, 0, 0;
	_vector3D UPd = 0, 1, 0;
	_vector3D IDLEd = 0, 0, 0;
END


BEGIN
	// control de estados por input
	write_var(0,1,450,0, currentState);
	SWITCH ( currentState )
		CASE IDLE:
			IF ( availableKeys[LEFTk].keyPressed )
			
				*currentDirection = WESTd;
				currentState = WALKING; 
				
			ELSEIF( availableKeys[RIGHTk].keyPressed  )
			
				*currentDirection = EASTd;
				currentState = WALKING;
				
			ELSEIF ( availableKeys[DOWNk].keyPressed )
				
			
				*currentDirection = SOUTHd;
				currentState = (WALKING);
				
			ELSEIF ( availableKeys[UPk].keyPressed )
				
				*currentDirection = NORTHd;
				currentState = (WALKING);
				
			ELSEIF ( availableKeys[CROUCHk].keyPressed )
			
				currentState = (CROUCH);
			
			ELSEIF ( availableKeys[JUMPk].keyPressed )
				IF( landed AND landedTime >= JUMP_DELAY)
				
					*currentDirection = UPd;
					currentState = (JUMPING);
					
				END
				
			END
		END //case
			
		CASE WALKING:
			IF ( availableKeys[LEFTk].keyPressed )
			
				*currentDirection = WESTd;
				currentState = (WALKING);
				IF ( availableKeys[DOWNk].keyPressed )
					
					resolveDirection( SOUTHd,  WESTd, *currentDirection);
					
				ELSEIF ( availableKeys[UPk].keyPressed )
					
					resolveDirection( NORTHd,  WESTd, *currentDirection);
					
				END
				
			ELSEIF( availableKeys[RIGHTk].keyPressed  )
			
				*currentDirection = EASTd;
				currentState = (WALKING);
				IF ( availableKeys[DOWNk].keyPressed )
					
					resolveDirection( SOUTHd,  EASTd , *currentDirection);
					
				ELSEIF ( availableKeys[UPk].keyPressed )
					
					resolveDirection( NORTHd,  EASTd, *currentDirection );
					
				END
				
			ELSE	
				IF ( availableKeys[DOWNk].keyPressed )
					
					*currentDirection = SOUTHd;
					currentState = (WALKING);
					
				ELSEIF ( availableKeys[UPk].keyPressed )
					
					*currentDirection = NORTHd;
					currentState = (WALKING);
					
				ELSEIF ( availableKeys[CROUCHk].keyPressed )
				
					currentState = (CROUCH);
				
				ELSEIF ( availableKeys[JUMPk].keyDown )
				
					*currentDirection =  UPd;
					currentState = (JUMPING);
				
				ELSE
					
					*currentDirection = IDLEd;
					currentState = (IDLE);
					
				END
			END
		END //case	
			
		CASE JUMPING:
			IF ( availableKeys[LEFTk].keyPressed )
			
				
			ELSEIF( availableKeys[RIGHTk].keyPressed  )
			
				
			ELSEIF ( availableKeys[DOWNk].keyPressed )
				
			
			ELSEIF ( availableKeys[UPk].keyPressed )
				
				
			ELSEIF (  availableKeys[JUMPk].keyPressed )
				
				currentDirection =  UPd;
				currentState = (JUMPING);
				
			ELSE
				
				currentDirection = IDLEd;
				currentState = (IDLE);
				
			END
		END	//case
			
		CASE CROUCH:
			IF ( availableKeys[LEFTk].keyPressed )
			
				
			ELSEIF( availableKeys[RIGHTk].keyPressed  )
			
				
			ELSEIF ( availableKeys[DOWNk].keyPressed )
				
			
			ELSEIF ( availableKeys[UPk].keyPressed )
				
			
			ELSEIF (  availableKeys[CROUCHk].keyPressed )
				
				currentState = (CROUCH);
				
			ELSE
				
				currentDirection = IDLEd;
				currentState = (IDLE);
			
			END
			
		END //case	
	END //switch
	return currentState;
END 